package com.sf.hackathons.app.ui.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;

import com.sf.hackathons.app.R;
import com.sf.hackathons.app.presenter.constract.LoginConstract;
import com.sf.hackathons.app.presenter.impl.LoginPresenter;
import com.sf.hackathons.lib.commui.base.BaseActivity;
import com.sf.hackathons.lib.ui.ClearEditText;
import com.sf.hackathons.lib.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity<LoginConstract.View, LoginConstract.Presenter> implements LoginConstract.View {


    @BindView(R.id.mEditUserName)
    ClearEditText mEditUserName;
    @BindView(R.id.mEditPwd)
    ClearEditText mEditPwd;

    @NonNull
    @Override
    public LoginConstract.Presenter createPresenter() {
        return new LoginPresenter();
    }

    @Override
    protected int initContentView() {
        return R.layout.activity_login;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initProcess(Bundle savedInstanceState) {


    }

    @OnClick({R.id.mBtnLogin})

    public void initListener(View v) {
        switch (v.getId()) {

            case R.id.mBtnLogin:
                loginIng();
                break;

        }

    }


    @Override
    public void loginIng() {
        if (TextUtils.isEmpty(mEditUserName.getText())) {
            ToastUtils.show("用户名为空");
            return;
        }
        if (TextUtils.isEmpty(mEditPwd.getText())) {
            ToastUtils.show("密码为空");
            return;
        }
        getPresenter().login(mEditUserName.getText().toString(), mEditPwd.getText().toString());

    }

    @Override
    public void loginSuccess() {
        dismissProgress();
        ToastUtils.show("登录成功");
        changeActivity(MainActivity.class);


    }

    @Override
    public void loginFail(String errCode, String errMsg) {
        dismissProgress();
        ToastUtils.show(errMsg);

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
